/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.calendarplan;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.calendarplan.Calendarplan;

/**
 * @author Administrator (email:357375084@qq.com)
 * @since 2013-02-27
 */
@Service("calendarplanService")
public class CalendarplanServiceImpl implements CalendarplanService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of Calendarplan
     ****************************************/
    public void insert(Calendarplan calendarplan) throws Exception {
        calendarplan.setPlanid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(calendarplan);
    }

    /****************************************
     * Update a instace of Calendarplan
     ****************************************/
    public void update(Calendarplan calendarplan) throws Exception {
        iDataSet4iBatis.update(calendarplan);
    }

    /****************************************
     * Delete a instace of Calendarplan
     ****************************************/
    public void delete(Calendarplan calendarplan) throws Exception {
        iDataSet4iBatis.delete(calendarplan);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(Calendarplan calendarplan) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(Calendarplan calendarplan) throws Exception {
        String statementId = calendarplan.getStatmentId();
        String mainId = calendarplan.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> calendarplanList = new ArrayList<BaseModel>();
        for (String id : ids) {
            Calendarplan model = new Calendarplan();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            calendarplanList.add(model);
        }
        iDataSet4iBatis.batchDelete(calendarplanList);
    }

    /****************************************
     * Query instaces of Calendarplan
     ****************************************/
    public List<BaseModel> queryAsList(Calendarplan calendarplan) throws Exception {
        String queryListStatement = "";
        if (calendarplan.isPaging()) {
            queryListStatement = calendarplan.getStatmentId();
            calendarplan.setStatmentId("Calendarplan.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(calendarplan);
            calendarplan.setTotalCount(baseModel.getTotalCount());
            calendarplan.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(calendarplan);
    }

    /****************************************
     * Query a instaces of Calendarplan
     ****************************************/
    public BaseModel queryAsObject(Calendarplan calendarplan) throws Exception {
        return iDataSet4iBatis.queryAsObject(calendarplan);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
